﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class msg
    {
        public static dynamic addOrEditDiscuss(int? did, int? parentDid, int? pid, string username, string title, string content, int len)
        {
            var sql = new Sql.SqlDataContext();
            Sql.Discuss d;
            if (did != null)
            {
                d = sql.Discuss.FirstOrDefault(row => row.did == did);
                if (d == null) return new
                    {
                        success = false,
                        msg = "帖子不存在"
                    };
            }
            else
            {
                d = new Sql.Discuss();
                d.parentDid = parentDid;
                d.pid = pid.Value;
                d.username = username;
                d.time = DateTime.Now;
            }
            d.title = title;
            d.content = content;
            d.len = len;
            if (did == null) sql.Discuss.InsertOnSubmit(d);
            sql.SubmitChanges();
            return new
            {
                success = true,
                d.did
            };
        }
    }
}